package org.libcsp.generic.api.enums;

import org.libcsp.generic.api.annotation.I18N;
import org.libcsp.generic.api.http.HttpStatus;

import java.lang.reflect.Field;

@SuppressWarnings("unused")
public interface IEnum {
    IEnum OK = HttpStatus.OK;
    IEnum BAD_REQUEST = HttpStatus.BAD_REQUEST;
    default int code(){
        return annotation().code();
    }

   default String msg(){
        return annotation().msg();
   }

    String name();

    default Field field(){
        Field field;
        try {
            field = this.getClass().getField(name());
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        return field;
    }

    default I18N annotation(){
        return field().getAnnotation(I18N.class);
    }
}
